<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="项目名称" prop="deptId">
                <el-select clearable style="width: 150px;" v-model="queryParams.deptId" placeholder="请选择项目名称">
                    <el-option v-for="item in deptList" :key="item.id" :label="item.label"
                        :value="item.id.toString()"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
                    v-hasPermi="['system:warningConfig:query']">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-table border v-loading="loading" :data="warningConfigList">
            <el-table-column label="项目名称" align="center" prop="deptName" show-overflow-tooltip width="100" />
            <el-table-column label="混凝土短信推送" align="center" prop="usingMsgHnt" width="120">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.usingMsgHnt" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="试验室短信推送" align="center" prop="usingMsgSy" width="120"> <template slot-scope="scope">
                    <el-tag v-if="scope.row.usingMsgSy" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="张拉压浆短信推送" align="center" prop="usingMsgZlyj" width="130"> <template
                    slot-scope="scope">
                    <el-tag v-if="scope.row.usingMsgZlyj" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="水稳拌合站短信推送" align="center" prop="usingMsgSw" min-width="140"> <template
                    slot-scope="scope">
                    <el-tag v-if="scope.row.usingMsgSw" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="沥青拌合站短信推送" align="center" prop="usingMsgLq" min-width="140"> <template
                    slot-scope="scope">
                    <el-tag v-if="scope.row.usingMsgLq" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="混凝土微信推送" align="center" prop="usingAppHnt" width="120"> <template
                    slot-scope="scope">
                    <el-tag v-if="scope.row.usingAppHnt" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="试验室微信推送" align="center" prop="usingAppSy" width="120"> <template slot-scope="scope">
                    <el-tag v-if="scope.row.usingAppSy" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="张拉压浆微信推送" align="center" prop="usingAppZlyj" width="130"> <template
                    slot-scope="scope">
                    <el-tag v-if="scope.row.usingAppZlyj" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="水稳拌合站微信推送" align="center" prop="usingAppSw" min-width="140"> <template
                    slot-scope="scope">
                    <el-tag v-if="scope.row.usingAppSw" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="沥青拌合站微信推送" align="center" prop="usingAppLq" min-width="140"> <template
                    slot-scope="scope">
                    <el-tag v-if="scope.row.usingAppLq" type="success">开启</el-tag>
                    <el-tag v-else type="danger">关闭</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="80">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['system:warningConfig:edit']">修改</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />

        <!--修改数据对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="300px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="140px">
                <el-form-item label="混凝土短信推送">
                    <el-switch v-model="form.usingMsgHnt" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="试验室短信推送">
                    <el-switch v-model="form.usingMsgSy" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="张拉压浆短信推送">
                    <el-switch v-model="form.usingMsgZlyj" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="水稳拌合站短信推送">
                    <el-switch v-model="form.usingMsgSw" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="沥青拌合站短信推送">
                    <el-switch v-model="form.usingMsgLq" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="混凝土微信推送">
                    <el-switch v-model="form.usingAppHnt" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="试验室微信推送">
                    <el-switch v-model="form.usingAppSy" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="张拉压浆微信推送">
                    <el-switch v-model="form.usingAppZlyj" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="水稳拌合站微信推送">
                    <el-switch v-model="form.usingAppSw" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="沥青拌合站微信推送">
                    <el-switch v-model="form.usingAppLq" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="0"></el-switch>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { businessDeptTreeTop } from "@/api/common/common";
import { nWarningUsingList, nWarningUsing } from "@/api/system/warningConfig";

export default {
    name: "warningConfig",
    data() {
        return {
            // 按钮loading
            buttonLoading: false,
            // 遮罩层
            loading: true,
            total: 0,
            warningConfigList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {

            },
            deptList: []
        };
    },
    created() {
        this.getList();
        this.getBusinessDeptTreeTop()
    },
    methods: {
        // 项目名称
        getBusinessDeptTreeTop() {
            businessDeptTreeTop().then((res) => {
                this.deptList = res.data
                this.getList()
            })
        },
        /** 查询数据列表 */
        getList() {
            this.loading = true;
            nWarningUsingList(this.queryParams).then(response => {
                this.warningConfigList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {};
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            console.log(this.queryParams);
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },

        /** 修改按钮操作 */
        handleUpdate(row) {
            this.loading = true;
            this.reset();
            const id = row.id || this.ids
            this.form = row;
            this.loading = false;
            this.open = true;
            this.title = "预警方式配置";
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    this.buttonLoading = true;
                    nWarningUsing(this.form).then(response => {
                        this.$modal.msgSuccess("预警方式配置成功");
                        this.open = false;
                        this.getList();
                    }).finally(() => {
                        this.buttonLoading = false;
                    });

                }
            });
        },

    }
};
</script>